package hot;

public class Num24 {
    public ListNode swapPairs(ListNode head) {
        if(head == null) return null;
        ListNode dummyhead = new ListNode(-1);
        dummyhead.next = head;
        ListNode cur = head.next;
        ListNode prev = head;
        while(cur != null) {
            int temp = cur.val;
            cur.val = prev.val;
            prev.val = temp;
            if(cur.next != null) {
                cur = cur.next.next;
                prev = prev.next.next;
            }else {
                break;
            }
        }
        return dummyhead.next;
    }
}
